import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

import React, { PureComponent } from 'react';
import { Button, Col, Form, Input, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Lov from 'components/Lov';
import cacheComponent from 'components/CacheComponent';
import intl from 'utils/intl';
import { VERSION_IS_OP } from 'utils/config';
import { FORM_COL_4_LAYOUT, FORM_FIELD_CLASSNAME, SEARCH_COL_CLASSNAME, SEARCH_FORM_ITEM_LAYOUT, SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
import { isTenantRoleLevel } from 'utils/utils';
var FormItem = Form.Item;
var Option = Select.Option;
var Search = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = cacheComponent({
  cacheKey: '/ciam/role/search-form'
}), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(Search, _PureComponent);

  var _super = _createSuper(Search);

  function Search(props) {
    var _this;

    _classCallCheck(this, Search);

    _this = _super.call(this, props);
    _this.state = {
      expandForm: false
    };
    return _this;
  } // 查询条件展开/收起


  _createClass(Search, [{
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    }
  }, {
    key: "onClick",
    value: function onClick() {
      var _this$props = this.props,
          _this$props$onQueryAl = _this$props.onQueryAll,
          onQueryAll = _this$props$onQueryAl === void 0 ? function (e) {
        return e;
      } : _this$props$onQueryAl,
          _this$props$form$getF = _this$props.form.getFieldsValue,
          getFieldsValue = _this$props$form$getF === void 0 ? function (e) {
        return e;
      } : _this$props$form$getF;
      var data = getFieldsValue() || {};
      var _data$labels = data.labels,
          labels = _data$labels === void 0 ? [] : _data$labels;
      var param = _isEmpty(labels) ? '' : labels.join(',');
      onQueryAll(_objectSpread(_objectSpread({}, data), {}, {
        labels: param
      }));
    }
  }, {
    key: "onReset",
    value: function onReset() {
      var _this$props$form$rese = this.props.form.resetFields,
          resetFields = _this$props$form$rese === void 0 ? function (e) {
        return e;
      } : _this$props$form$rese;
      resetFields();
    }
  }, {
    key: "renderSiteSearchForm",
    value: function renderSiteSearchForm() {
      var _this$props2 = this.props,
          _this$props2$code = _this$props2.code,
          code = _this$props2$code === void 0 ? [] : _this$props2$code,
          _this$props2$roleLeve = _this$props2.roleLevel,
          roleLevel = _this$props2$roleLeve === void 0 ? [] : _this$props2$roleLeve,
          _this$props2$searchLa = _this$props2.searchLabels,
          searchLabels = _this$props2$searchLa === void 0 ? [] : _this$props2$searchLa,
          _this$props2$form$get = _this$props2.form.getFieldDecorator,
          getFieldDecorator = _this$props2$form$get === void 0 ? function (e) {
        return e;
      } : _this$props2$form$get;
      var expandForm = this.state.expandForm;
      return /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, Object.assign({
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.name").d('角色名称')
      }), getFieldDecorator('name')( /*#__PURE__*/React.createElement(Input, {
        className: FORM_FIELD_CLASSNAME
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.level").d('角色层级')
      }), getFieldDecorator('level')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        className: FORM_FIELD_CLASSNAME
      }, roleLevel.filter(function (item) {
        return item.value !== 'org';
      }).map(function (n) {
        return /*#__PURE__*/React.createElement(Option, {
          key: n.value,
          value: n.value
        }, n.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.roleSource").d('角色来源')
      }), getFieldDecorator('roleSource')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        className: FORM_FIELD_CLASSNAME
      }, code.map(function (n) {
        return /*#__PURE__*/React.createElement(Option, {
          key: n.value,
          value: n.value
        }, n.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(FormItem, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.toggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get("cpaas.common.button.viewMore").d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.onReset.bind(this)
      }, intl.get("cpaas.common.button.reset").d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.onClick
      }, intl.get("cpaas.common.button.search").d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        style: {
          display: expandForm ? '' : 'none'
        }
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.tenant").d('所属租户')
      }), getFieldDecorator('tenantId')( /*#__PURE__*/React.createElement(Lov, {
        className: FORM_FIELD_CLASSNAME,
        code: isTenantRoleLevel() ? 'CPFM.TENANT.ORG' : 'CPFM.TENANT'
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.labels").d('标签')
      }), getFieldDecorator('labels')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        mode: "multiple",
        className: FORM_FIELD_CLASSNAME
      }, searchLabels.map(function (n) {
        return /*#__PURE__*/React.createElement(Option, {
          key: n.id,
          value: n.name
        }, n.name);
      })))))));
    }
  }, {
    key: "renderTenantSearchForm",
    value: function renderTenantSearchForm() {
      var _this$props3 = this.props,
          _this$props3$form$get = _this$props3.form.getFieldDecorator,
          getFieldDecorator = _this$props3$form$get === void 0 ? function (e) {
        return e;
      } : _this$props3$form$get,
          _this$props3$searchLa = _this$props3.searchLabels,
          searchLabels = _this$props3$searchLa === void 0 ? [] : _this$props3$searchLa;
      return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, SEARCH_FORM_ROW_LAYOUT, /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.name").d('角色名称')
      }), getFieldDecorator('name')( /*#__PURE__*/React.createElement(Input, {
        className: FORM_FIELD_CLASSNAME
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.labels").d('标签')
      }), getFieldDecorator('labels')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        mode: "multiple"
      }, searchLabels.map(function (n) {
        return /*#__PURE__*/React.createElement(Option, {
          key: n.id,
          value: n.name
        }, n.name);
      }))))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(FormItem, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.onReset.bind(this)
      }, intl.get("cpaas.common.button.reset").d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.onClick
      }, intl.get("cpaas.common.button.search").d('查询'))))));
    }
  }, {
    key: "render",
    value: function render() {
      if (!VERSION_IS_OP && !isTenantRoleLevel()) {
        return this.renderSiteSearchForm();
      }

      return this.renderTenantSearchForm();
    }
  }]);

  return Search;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onClick", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "onClick"), _class2.prototype)), _class2)) || _class) || _class);
export { Search as default };